// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import $ from 'jquery'
import './assets/commn/animate.min.css'
import './assets/boostrap/css/bootstrap.min.css'
import './assets/boostrap/js/bootstrap.min.js'
import 'element-ui/lib/theme-default/index.css'
import './assets/font-awesome-4.7.0/css/font-awesome.min.css'
import "./assets/commn/commn.scss";
import store from './store'
Vue.prototype.store = store
import Vue from 'vue'
// //引入vuex状态管理插件
// import Vuex from 'vuex'
// Vue.use(Vuex)
import App from './App'
import router from './router'
// import store from './store/index';
//引入ajax插件（vue-axios）
import axios from 'axios'
import Qs from 'qs'
Vue.prototype.$axios = axios;
//引入API拦截器
import "./ajax"
//引入element-ui库
import {
  Pagination, Dialog, Autocomplete, Dropdown, DropdownMenu, DropdownItem, Menu, Submenu, MenuItem, MenuItemGroup,
  Input, InputNumber, Radio, RadioGroup, RadioButton, Checkbox, CheckboxGroup, Switch, Select, Option,
  OptionGroup, Button, ButtonGroup, Table, TableColumn, DatePicker, TimeSelect, TimePicker, Popover, Tooltip,
  Breadcrumb, BreadcrumbItem, Form, FormItem, Tabs, TabPane, Tag, Tree, Alert, Slider, Icon, Row, Col, Upload,
  Progress, Spinner, Badge, Card, Rate, Steps, Step, Carousel, Scrollbar, CarouselItem, Collapse, CollapseItem,
  Cascader, ColorPicker, Loading, MessageBox, Message
} from 'element-ui'
Vue.use(Pagination);
Vue.use(Dialog);
Vue.use(Autocomplete);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Input);
Vue.use(InputNumber);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(RadioButton);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Switch);
Vue.use(Select);
Vue.use(Option);
Vue.use(OptionGroup);
Vue.use(Button);
Vue.use(ButtonGroup);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(DatePicker);
Vue.use(TimeSelect);
Vue.use(TimePicker);
Vue.use(Popover);
Vue.use(Tooltip);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Tag);
Vue.use(Tree);
Vue.use(Alert);
Vue.use(Slider);
Vue.use(Icon);
Vue.use(Row);
Vue.use(Col);
Vue.use(Upload);
Vue.use(Progress);
Vue.use(Spinner);
Vue.use(Badge);
Vue.use(Card);
Vue.use(Rate);
Vue.use(Steps);
Vue.use(Step);
Vue.use(Carousel);
Vue.use(Scrollbar);
Vue.use(CarouselItem);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Cascader);
Vue.use(ColorPicker);

Vue.use(Loading.directive);
//全局注册element-ui的组件
Vue.prototype.$loading = Loading.service;
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$notify = Notification;
Vue.prototype.$message = Message;

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {App}
});

router.beforeEach(function (to, from, next) {
  next(vm => {
    // vm.post = post
  })
  // console.log(to);
  // console.log(from);
  // console.log(next);
  console.log('路由变化了');
  window.scrollTo(0, 0);
})

//--------------------------------------全局请求拦截（代码开始）-----------------------------------------------------------
//axios配置
axios.defaults.baseURL = '/conferenceSystem';
axios.defaults.timeout = 2500;

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  // console.log('请求成功！');
  return config;
}, function (error) {
  // 对请求错误做些什么
  // console.log('请求失败！');
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(
  (response) => {
    // 对响应数据做点什么
    // console.log('响应成功！');
    // console.log(response);
    //全局拦截code != 10000的响应
    if (response.data && response.data.code && response.data.code != '10000') {
      if (response.data.msg) {
        Message({
          message: response.data.msg,
          type: 'warning'
        });
      }
    } else {
      return response.data;
    }
    //全局拦截会话失效的响应
    if (response.headers('sessionInvalid') || (response.data && response.data.code == '11111')) {
      Message({
        message: response.data.msg,
        type: 'warning'
      });
      router.push({name: 'login'})
    }
  },
  (error) => {
    // 对响应错误做点什么
    console.log('响应失败！');
    return Promise.reject(error);
  });
//--------------------------------------全局请求拦截（代码结束）-----------------------------------------------------------
